import apiClient from "@/api/axios.js";

export class RoadHazardApi {
    // 更新灾害状态
    static async updateDisasterStatus(disasterID, status, token) {
        try {
            const response = await apiClient.put(
                '/road-hazard/update-status',
                {},
                {
                    params: { disasterID, status },
                    headers: {
                        'Content-Type': 'application/json',
                        token, // 添加用户身份校验的 token
                    },
                }
            );
            return response.data; // 返回更新结果
        } catch (error) {
            throw new Error(error.message || '更新灾害状态失败');
        }
    }

    // 上传灾害
    static async publishDisaster(disasterInfo, userID, latitude, longitude, videoUrl,) {
        try {
            const response = await apiClient.post(
                '/road-hazard/publish',
                { disasterInfo, userID, latitude, longitude, video_url:videoUrl },
                {
                    headers: {
                        'Content-Type': 'application/json',
                    },
                }
            );
            return response.data; // 返回灾害发布结果
        } catch (error) {
            throw new Error(error.message || '上传灾害失败');
        }
    }
}
